class ActsAsRatableMigration < ActiveRecord::Migration
  def self.up
    create_table :rates do |t|
      t.integer :ratable_id
      t.string :ratable_type, :limit => 32
      t.integer :votes, :null=>false, :default => 0
      t.integer :total_score, :null=>false,  :default => 0
      
      t.timestamps
    end
    
    create_table :ratings do |t| 
      t.references :rate
      t.references :user
      t.integer :score
      
      t.datetime :create_at
    end
    
    add_index :rates, [:ratable_id,:ratable_type],
              :unique => true, :name => 'ratable_key'

    add_index :ratings, [:rate_id,:user_id],
              :unique => true, :name => 'user_rating_key'
  end

  def self.down
    drop_table :rates
    drop_table :ratings
  end

end
